﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "学生成绩替代");
		
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		
		subjectId = event.getArg("SBJ");
		grade = event.getArg("GRD");
		markId = event.getArg("SCMID");
		
		studentId = event.getArg("STU");
		
		
		/* 学生所有已通过成绩明细 */
		sql = "SELECT 
					b.course_name, b.course_credit, b.cid, b.course_code,  
					a.scm_id, 
					a.retaking, a.mark_mode, 
					a.mark_result, a.mark_note, 
					a.mark_resit, a.mark_renote, a.mark_resit_limit, 
					c.prop_name, 
					d.institute_short 
				FROM t_student_mark a 
					 INNER JOIN t_course b ON b.cid = a.cid 
					 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
					 INNER JOIN t_institute d ON d.institute_id = b.institute_id 
				WHERE 
					  a.stu_id = :stuId 
					  AND 
					  (
						  a.mark_result >= 60 OR a.mark_resit >= 60 
					  )
				ORDER BY b.course_name ";
		
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="stuId", value=studentId, cfsqltype="cf_sql_varchar" );
			
		rs_mark = queryObj.execute( sql=sql ).getResult();
		
		
		/* 读取需要替换的成绩 */
		sql = "SELECT 
					b.course_name, b.course_credit, b.cid, b.course_code,  
					a.scm_id, 
					a.retaking, a.mark_mode, 
					a.mark_result, a.mark_note, 
					a.mark_resit, a.mark_renote, a.mark_resit_limit, 
					c.prop_name, 
					d.institute_short  
				FROM t_student_mark a 
					 INNER JOIN t_course b ON b.cid = a.cid 
					 INNER JOIN t_course_prop c ON c.prop_id = a.prop_id 
					 INNER JOIN t_institute d ON d.institute_id = b.institute_id 
				WHERE 
					a.scm_id = :markId ";
							
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="markId", value=markId, cfsqltype="cf_sql_varchar" );
		
		rs_mark_orginal = queryObj.execute( sql=sql ).getResult();
		
		
		currentTab = event.getArg("TabID", "labDetail");
		
		passArgs = structNew();
		structInsert( passArgs, "SBJ", subjectId, true );
		structInsert( passArgs, "GRD", grade, true );
		structInsert( passArgs, "SCMID", markId, true );
		structInsert( passArgs, "STU", studentId, true );
		
		/* 搜索课程 */
		keyword = event.getArg("Keywords");
		
		rs_search = queryNew("course_name, course_credit, cid, course_code, scm_id, retaking, mark_mode, mark_result, mark_note, mark_resit, mark_renote, mark_resit_limit, prop_name");

		if ( len(keyword) ) {
			
			currentTab = event.getArg("TabID", "labSearch");
			structInsert( passArgs, "Keywords", keyword, true );

			sql = "SELECT * FROM query 
					WHERE 
						course_name LIKE :condition 
						OR 
						course_code LIKE :condition";
					
			queryObj = new Query( dbtype="query", maxRows=30 );
			queryObj.setAttributes( query=rs_mark );
			queryObj.addParam( name="condition", value=keyword&"%", cfsqltype="cf_sql_varchar" );
			
			rs_search = queryObj.execute( sql=sql ).getResult();

		}
				
		/*成绩替代*/
		markReplaceId = event.getArg("SCMID_R");
		
		rs_mark_replace = queryNew("cid");
		
		if( len(markReplaceId) ){
			
			sql = "SELECT *
					FROM query 
					WHERE 
						scm_id = :markReplaceId ";
					
			queryObj = new Query( dbtype="query" );
			queryObj.setAttributes( query=rs_mark );
			
			queryObj.addParam( name="markReplaceId", value=markReplaceId, cfsqltype="cf_sql_varchar" );
			
			rs_mark_replace = queryObj.execute( sql=sql ).getResult();
			
			currentTab = event.getArg("TabID", "labReplace");
			
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('gradProfileView', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">返回</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>学生成绩替代
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labDetail">class="active"</cfif> id="labDetail" tabTarget="Detail">已通过课程一览表</span>
							<cfif len(markReplaceId) >
								<span <cfif currentTab eq "labReplace">class="active"</cfif> id="labReview" tabTarget="Replace">成绩替代</span>
							</cfif>
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabTarget="Search">搜索课程</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Detail" class="tabContent">

					<div class="noticeBlock">
						<h3>需替换的成绩</h3>
						<hr/>
					</div>
					
					<cfif rs_mark_orginal.recordCount>
						
						<cfset markFinal = markAdvice.getMarkResult( rs_mark_orginal.mark_mode, rs_mark_orginal.mark_result, rs_mark_orginal.mark_note, rs_mark_orginal.mark_resit, rs_mark_orginal.mark_renote, rs_mark_orginal.mark_resit_limit ) />
						
						<table class="UItable markFailure">

							<tr class="cellDivide cellHeader">
								<td width="80">课程号</td>
								<td>课程</td>
								<td width="60">任课单位</td>
								<td width="30">学分</td>
								<td width="60" align="center">考核成绩</td>
							</tr>
							<tbody>
								<tr class="cellDivide">
									<td><span class="number"><cfoutput>#rs_mark_orginal.course_code#</cfoutput></span></td>
									<td><cfoutput>#rs_mark_orginal.course_name#</cfoutput></td>									
									<td><cfoutput>#rs_mark_orginal.institute_short#</cfoutput></td>	
									<td><span class="number"><cfoutput>#rs_mark_orginal.course_credit#</cfoutput></span></td>
									<td align="center">
										<cfif isNumeric(markFinal)>
												<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
											<cfelse>
												<cfoutput>#markFinal#</cfoutput>
										</cfif>
									</td>
								</tr>
							</tbody>
							
						</table>
						
					</cfif>
					
					<div class="noticeBlock">
						<h3>已通过课程汇总</h3>
						<p><span class="img icon16x16 message"></span>该学生所有通过课程 <em><cfoutput>#rs_mark.recordCount#</cfoutput></em> 门, 下列是该专学生已通过课程汇总 </p>
						<hr/>
					</div>
					
					<cfset row = 0 />
					<table class="UItable markPassed">

						<tr class="cellDivide cellHeader">
							<td width="25"></td>
							<td width="80">课程号</td>
							<td>课程</td>
							<td width="60">任课单位</td>
							<td width="50" align="center">学分</td>
							<td width="60" align="center">考核成绩</td>
							<td width="18"></td>
						</tr>
						
						<tbody>
							<cfloop query="rs_mark">
									
								<cfset row++ />
								<cfset structInsert( passArgs, "SCMID_R", rs_mark.scm_id, true ) />
								
								<cfset markFinal = markAdvice.getMarkResult( rs_mark.mark_mode, rs_mark.mark_result, rs_mark.mark_note, rs_mark.mark_resit, rs_mark.mark_renote, rs_mark.mark_resit_limit ) />
								
								<tr class="cellDivide">
									<td align="center"><span class="number"><cfoutput>#row#</cfoutput></span></td>
									<td><span class="number"><cfoutput>#rs_mark.course_code#</cfoutput></span></td>
									<td><cfoutput>#rs_mark.course_name#</cfoutput></td>
									<td align="center"><cfoutput>#rs_mark.institute_short#</cfoutput></td>	
									<td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_mark.course_credit, "_.__" )#</cfoutput></span></td>
									<td align="center">
										<cfif isNumeric(markFinal)>
												<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
											<cfelse>
												<cfoutput>#markFinal#</cfoutput>
										</cfif>
									</td>
									<td><a title="成绩替代" href="<cfoutput>#buildURL('signMarkReplace', passArgs)#</cfoutput>" class="operation replaceCourse"></a></td>
								</tr>
								
							</cfloop>
							
							<cfset structDelete( passArgs, "SCMID_R" ) />
							
						</tbody>
					</table>
					
				</div>
				
				<cfif len(markReplaceId) >
				
					<div id="Replace" class="tabContent">
					
						<div class="noticeBlock">
							<h3><cfoutput>#rs_mark_orginal.course_name#</cfoutput>(<cfoutput>#rs_mark_orginal.course_code#</cfoutput>)即将被替代</h3>
							<p><span class="img icon16x16 message"></span>课程将由 <cfoutput>#rs_mark_replace.course_name#</cfoutput><em>(<cfoutput>#rs_mark_replace.course_code#</cfoutput>)</em> 替代, 请根据实际情况设置替代事项. </p>
							<hr>
						</div>
						
						<form id="formCondition" class="formWrapper " method="post" action="<cfoutput>#BuildURL('studentMarkReplaceDo', passArgs)#</cfoutput>">
						
							<input type="hidden" name="oldMarkId" value="<cfoutput>#rs_mark_orginal.scm_id#</cfoutput>"/>
							<input type="hidden" name="newMarkId" value="<cfoutput>#rs_mark_replace.scm_id#</cfoutput>"/>
							
							<div class="label">
								<b>原课程</b>
								<div class="secondRow">
									<table class="UItable markFailure">
										<tr class="cellDivide cellHeader">
											<td width="80">课程号</td>
											<td>课程</td>
											<td width="60">任课单位</td>
											<td width="30">学分</td>
											<td width="60" align="center">考核成绩</td>
										</tr>
										<tbody>
											<cfset markFinal = markAdvice.getMarkResult( rs_mark_orginal.mark_mode, rs_mark_orginal.mark_result, rs_mark_orginal.mark_note, rs_mark_orginal.mark_resit, rs_mark_orginal.mark_renote, rs_mark_orginal.mark_resit_limit ) />
											<tr class="cellDivide">
												<td><span class="number"><cfoutput>#rs_mark_orginal.course_code#</cfoutput></span></td>
												<td><cfoutput>#rs_mark_orginal.course_name#</cfoutput></td>
												<td align="center"><cfoutput>#rs_mark_orginal.institute_short#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#rs_mark_orginal.course_credit#</cfoutput></span></td>
												<td align="center">
													<cfif isNumeric(markFinal)>
															<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
														<cfelse>
															<cfoutput>#markFinal#</cfoutput>
													</cfif>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
							
							<div class="label">
								<b>替代课程</b>
								<div class="secondRow">
									<table class="UItable markPassed">
										<tr class="cellDivide cellHeader">
											<td width="80">课程号</td>
											<td>课程</td>
											<td width="60">任课单位</td>
											<td width="30">学分</td>
											<td width="60" align="center">考核成绩</td>
										</tr>
										<tbody>
											<cfset markFinal = markAdvice.getMarkResult( rs_mark_replace.mark_mode, rs_mark_replace.mark_result, rs_mark_replace.mark_note, rs_mark_replace.mark_resit, rs_mark_replace.mark_renote, rs_mark_replace.mark_resit_limit ) />
											<tr class="cellDivide">
												<td><span class="number"><cfoutput>#rs_mark_replace.course_code#</cfoutput></span></td>
												<td><cfoutput>#rs_mark_replace.course_name#</cfoutput></td>									
												<td align="center"><cfoutput>#rs_mark_replace.institute_short#</cfoutput></td>
												<td align="center"><span class="number"><cfoutput>#rs_mark_replace.course_credit#</cfoutput></span></td>
												<td align="center">
													<cfif isNumeric(markFinal)>
															<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
														<cfelse>
															<cfoutput>#markFinal#</cfoutput>
													</cfif>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
							
							<div class="label">
								<b>可选项</b>
								<div class="secondRow">
									<table>
										<tr>
											<td><input name="toSubject" type="checkbox" class="typeCheckbox" value="1" /> 该替代关系适用于整个专业</td>
										</tr>
										<tr>
											<td><input name="toCourse" type="checkbox" class="typeCheckbox" checked="checked" value="1" /> 如果学生该门课程有多个不及格成绩, 对所有成绩都使用这个规则进行标注</td>
										</tr>
									</table>
								</div>
							</div>
							
							<hr/>
								
							<div class="lable">
								<input class="button" type="submit" value="确认替代">
							</div>
							
						</form>
					
					</div>
				</cfif>
				
				<div id="Search" class="tabContent">
					
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('signMarkReplace', passArgs)#</cfoutput>">
						
						<div class="label">
							<b>课程号或名字</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
					<cfif rs_search.recordCount>

						<cfset row = 0 />
						<table class="UItable markPassed">

							<tr class="cellDivide cellHeader">
								<td width="25"></td>
								<td width="80">课程号</td>
								<td>课程</td>
								<td width="60">任课单位</td>
								<td width="50" align="center">学分</td>
								<td width="60" align="center">考核成绩</td>
								<td width="18"></td>
							</tr>
						
							<tbody>
								<cfloop query="rs_search">
									
									<cfset row++ />
									<cfset structInsert( passArgs, "SCMID_R", rs_search.scm_id, true ) />
								
									<cfset markFinal = markAdvice.getMarkResult( rs_search.mark_mode, rs_search.mark_result, rs_search.mark_note, rs_search.mark_resit, rs_search.mark_renote, rs_search.mark_resit_limit ) />
								
									<tr class="cellDivide">
										<td align="center"><span class="number"><cfoutput>#row#</cfoutput></span></td>
										<td><span class="number"><cfoutput>#rs_search.course_code#</cfoutput></span></td>
										<td><cfoutput>#rs_search.course_name#</cfoutput></td>
										<td align="center"><cfoutput>#rs_search.institute_short#</cfoutput></td>
										<td align="center"><span class="numeric"><cfoutput>#numberFormat( rs_search.course_credit, "_.__" )#</cfoutput></span></td>
										<td align="center">
											<cfif isNumeric(markFinal)>
													<span class="number"><cfoutput>#replace( markFinal, ".0", "" )#</cfoutput></span>
												<cfelse>
													<cfoutput>#markFinal#</cfoutput>
											</cfif>
										</td>
										<td><a title="成绩替代" href="<cfoutput>#buildURL('signMarkReplace', passArgs)#</cfoutput>" class="operation replaceCourse"></a></td>
									</tr>
								
								</cfloop>
								
								<cfset structDelete( passArgs, "CID_R" ) />
							
							</tbody>
						</table>
					
					</cfif>
				
				</div>

			</div>
		</li>
	</ul>
</div>
